Find_If_Tile_Occupied_By_Building:
 
 BIT Object_Ready_To_Add, (IY + asm_flag1)
 ret nz


 ld hl, (Objects_Address) 

 
 ld bc, 11
 or a
 sbc hl, bc
 push hl
 pop ix

 ld b, 201 

_
 
 ld a,b

 or a
 jp z, ++_
 dec a
 ld bc, 11
 add ix, bc
 ld b,a
 

 ld a, (IX + 10)
 or a
 jr z, -_


 ld de, (MapX)
 

 ld l, (ix)
 ld h, (ix+1)
 
 
 or a
 sbc hl, de 
 ld d,h
 ld e,l
 push bc
 ld b,0
 ld c, (ix + 9); Building width
 add hl, bc
 ex de, hl
 pop bc

;Adjust for negative numbers

 ld a,(Select_Cursor_X)
 ld c, a
 

 ld a, h
 cp 255
 call z, Adjust_For_Negative_Numbers
 ld a,c

 
 cp l
 jr c, -_
 cp e
 jr nc, -_



 ld de, (MapY)
 



 ld l, (ix+2)
 ld h, (ix+3)
 
 
 or a
 sbc hl, de 
		


 ld d,h
 ld e,l
 push bc
 ld b,0
 ld c, (ix + 10); Building width
 add hl, bc
 ex de, hl
 pop bc


 ld a,(Select_Cursor_Y)
 ld c,a
 ld a, h
 cp 255
 call z, Adjust_For_Negative_Numbers



 ld a,c
 cp l
 jr c, -_

 cp e
 jr nc, -_


_

 ld a, 1 ;This means that there is a building there.
 ld b, (IX + 4) ;B contains the structure type


 ret
_

 ld a,0

 ret


Adjust_For_Negative_Numbers:

 ld a, l
 neg
 ld d, a
 ld a, l
 add a,d
 ld l,a
 ld a,e
 add a, d
 ld e,a
 ld a,c
 add a, d
 ld c,a
 ret
 